package com.sec.android.app.myfiles.shadow.android;

import android.os.storage.StorageVolume;

import com.sec.android.app.myfiles.info.AppConstants;
import com.sec.android.app.myfiles.util.StorageVolumeUtil;

import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;

import java.util.Locale;

/**
 * Created by jaebae on 2016-07-04.
 */
@Implements(StorageVolumeUtil.class)
public class ShadowStorageVolumeUtil {

    @Implementation
    public static boolean isSdStorage(StorageVolume storageVolume) {
        return isPrefixPath(storageVolume, "sd");
    }

    @Implementation
    public static boolean isUsbStorage(StorageVolume storageVolume) {
        return isPrefixPath(storageVolume, "usb");
    }

    private static boolean isPrefixPath(StorageVolume storageVolume, String preFix) {
        boolean bRet = false;
        String path = ShadowStorageManager.getVolumePath(storageVolume);

        if (!path.startsWith(AppConstants.StoragePath.INTERNAL_ROOT)) {
            bRet = path.toLowerCase(Locale.getDefault()).contains(preFix);
        }
        return bRet;
    }

}
